﻿using com.haoest.Utils.Forms;
using com.haoest.Utils.Forms.Buttons;
using com.haoest.QrPortal.FunctionPanels;
using com.haoest.Utils.Environment;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace com.haoest.QrPortal
{
    public partial class MainForm : BlankForm
    {
        public MainForm()
        {
            InitializeComponent();
            toolStripStatusLabel_Version.Text = "版本：" + Info.AssemblyVersion;
            tableLayoutPanel_Full.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tableLayoutPanel_Full, true, null);
            flowLayoutPanel_Buttons.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(flowLayoutPanel_Buttons, true, null);
            richButton_Welcome.Tag = WelcomePanel.Instanse;
            richButton_ShareWifi.Tag = ShareWifiPanel.Instance;
            richButton_AddDevice.Tag = AddDevicePanel.Instance;
            richButton_QuickTransfer.Tag = QuickTransferPanel.Instance;
            richButton_TransferFile.Tag = TransferFilePanel.Instance;
        }
        private Point startPoint;


        /// <summary>
        /// 窗口标题栏鼠标移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LabelWindowName_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Left = startPoint.X + MousePosition.X;
                this.Top = startPoint.Y + MousePosition.Y;
            }
        }

        /// <summary>
        /// 窗口标题栏鼠标按下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LabelWindowName_MouseDown(object sender, MouseEventArgs e)
        {
            startPoint.X = this.Left - MousePosition.X;
            startPoint.Y = this.Top - MousePosition.Y;
        }

        /// <summary>
        /// 解决闪烁问题
        /// </summary>
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }

        private void RichButtons_Click(object sender, EventArgs e)
        {
            mainPanel.Controls.Clear();
            mainPanel.Controls.Add((UserControl)((RichButton)sender).Tag);

            ((BasePanel)((RichButton)sender).Tag).Reload();
            richButton_Welcome.Clicked = false;
            richButton_AddDevice.Clicked = false;
            richButton_QuickTransfer.Clicked = false;
            richButton_ShareWifi.Clicked = false;
            richButton_TransferFile.Clicked = false;
            ((RichButton)sender).Clicked = true;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            RichButtons_Click((object)richButton_Welcome, e);
        }

        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {

        }
    }
}
